<?php
/**
 * The content template for displaying employee posts. This is used by the archive and single post templates.
 *
 * @package LFCC 
 * @subpackage Employee_Directory
 * @since LFCC 1.0
 *
 */
?>

				<div class="employee">
				<?php the_post_thumbnail('medium',array('class'=>'employeepic')); ?>
				<table class="employee">
					<tr>
						<th scope="row">Name:</th>
						<?php if ( !is_singular() ) : ?>
							<td><a href="<?php the_permalink(); ?>"><?php echo get_post_meta($post->ID, 'first_name', true).' '.get_post_meta($post->ID, 'last_name', true); ?></a></td>
						<?php else: ?>
							<td><?php echo get_post_meta($post->ID, 'first_name', true).' '.get_post_meta($post->ID, 'last_name', true); ?></td>
						<?php endif; ?>
					</tr>

					<tr>
						<th scope="row">Position:</th>
						<td><?php echo get_post_meta($post->ID, 'position', true); ?></td>
					</tr>

					<tr>
						<th scope="row">College unit:</th>
						<?php $college_unit_id = get_post_meta($post->ID, 'college_unit', true); ?>
						<?php $college_unit_term = get_term($college_unit_id,'college_unit'); ?>
						<td><?php echo $college_unit_term->name;  ?></td>
					</tr>

					<tr>
						<th scope="row">Employee category:</th>
						<?php $employee_type_id = get_post_meta($post->ID, 'employee_type', true); ?>
						<?php $employee_type_term = get_term($employee_type_id,'employee_type'); ?>
						<td><?php echo $employee_type_term->name;  ?></td>
					</tr>

					<tr>
						<th scope="row">Office location:</th>
						<?php $campus_id = get_post_meta($post->ID, 'campus', true); ?>
						<?php $campus_term = get_term($campus_id, 'campus'); ?>
						<?php $campus_building_id = get_post_meta($post->ID, 'campus_building', true); ?>
						<?php $campus_building_term = get_term($campus_building_id, 'campus_building'); ?>
						<td><?php echo $campus_term->name.($campus_building_term->name ? ' &ndash; '.$campus_building_term->name : '' ).' &ndash; '.get_post_meta($post->ID, 'office_location', true);  ?></td>
					</tr>

					<tr>
						<th scope="row">Disciplines Taught:</th>
						<?php $discipline_ids = get_post_meta($post->ID, 'disciplines_taught', true); // Unlike the "Employee Category" and "Office Location" custom fields, that only have one option, this have multi-select enabled. That's why it comes back as an array even with the "no array" option set to true - RMD  ?>
						<td>
						<?php
						foreach ($discipline_ids as $key=>$discipline_id) {
							$discipline_terms[$discipline_id] = get_term($discipline_id,'course_discipline')->name; 
						}
						$i = 0;
						// This allows the list of "Disciplines Taught" to be listed as a proper comma list (e.g. "Arts, Biology, and Computer Science" or "Arts and Biology") - RMD
						foreach ($discipline_terms as $discipline_id=>$discipline_term) {
							$i++;	
							switch (count($discipline_terms)-$i) {
							case 0:
								echo $discipline_term;
							break;
							case 1: 
								echo $discipline_term . ' and ';
							break;
							default:
								echo $discipline_term . ', ';
							break;
							}
						}
						 ?>
						</td>
					</tr>

					<?php
					// For the Fax and Telephone Numbers
					function format_telephone_number($phone_number,$area_code=540) { 
						$phone_number = preg_replace('/(\d{3}|)(\d{3})(\d{4})/',$area_code.'-$2-$3',$phone_number);
						return $phone_number;
					} 
					?>
					<tr>
						<th scope="row">Telephone number:</th>
						<td><?php echo format_telephone_number(get_post_meta($post->ID, 'phone_number', true)); ?></td>
					</tr>

					<tr>
						<th scope="row">Fax number:</th>
						<td><?php echo format_telephone_number(get_post_meta($post->ID, 'fax_number', true)); ?></td>
					</tr>
					<tr>
						<th scope="row">E-mail address:</th>
						<?php $email = get_post_meta($post->ID, 'email', true); ?>
						<td><a href="mailto:<?php echo $email ?>"><?php echo $email; ?></a></td>
					</tr>
					<tr>
						<th scope="row">Alternate Contact:</th>
						<?php $alternate_contact_id = get_post_meta($post->ID, 'alternate_contact', true); ?>
						<?php $alternate_contact_post = get_post($alternate_contact_id, 'alternate_contact'); ?>
						<td><a href="<?php echo $alternate_contact_post->guid; ?>"><?php echo $alternate_contact_post->post_title; ?></a></td>
					</tr>
				</table>
